package algotithm.acwing.test104;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

/**
 * @author zhouyanxiang
 * @Date 2021-01-2021/1/9-12:24
 */
public class Solution {

    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(reader.readLine());
        String[] nums = reader.readLine().split(" ");
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = Integer.parseInt(nums[i]);
        }
        reader.close();
        int res = 0;
        Arrays.sort(arr);
        for (int i = 0; i < arr.length/2; i++) {
            res += (arr[arr.length - 1 - i] - arr[i]);
        }
        System.out.println(res);
    }

}
